import { Injectable } from '@nestjs/common';
import cloudbase from '@cloudbase/node-sdk';

// 注意以下几个参数是必填的,文档上说的是非必填
const app = cloudbase.init({
  secretId: process.env.SECRET_ID,
  secretKey: process.env.SECRET_KEY,
  env: process.env.ENV,
  // 根据你创建的区域来写,目前只有上海(ap-shanghai)、广州(ap-guangzhou)
  region: process.env.REGION
})


// 1. 获取数据库引用
const db = app.database();

@Injectable()
export class AppService {
  getHello(): string {
    return 'Hello World!';
  }

  async getUser(): Promise<any> {
    return await db.collection('nest-cloundbase')
      .get()
  }

  async createAccount(data: any): Promise<any> {
    const res = await db.collection('nest-cloundbase')
      .add({
        ...data,
      });
    return res;
  }
}
